program gmm_poiend
	syntax varlist if, at(name)
	quietly{
		tempvar mu
		matrix score double `mu'=`at' `if', eq(#1)
		replace `mu'=exp(`mu')
		local mylhs: coleq `at'
		local mylhs: word 1 of `mylhs'
		tempvar mubar ybar
		bys id: egen double `mubar'=mean(`mu') `if'
		bys id: egen double `ybar'=mean(`mylhs') `if'
		replace `varlist'=(`mylhs'/`mu')-(`ybar'/`mubar') `if'
	}
end

